package ch.sfug.anim.tween {
	import ch.sfug.anim.IAnimation;	
	
	import flash.events.Event;
	import flash.events.EventDispatcher;	

	/**
	 * this class simply handles the eventlistener registration when the tween is a composition.
	 * this is used to show only the functions that are necessary and do some correct casts. for example to 
	 * cast the target of the mover to displayobject.
	 * 
	 * @author mich
	 */
	public class CompositeTween extends EventDispatcher implements IAnimation {

		protected var tween:AbstractTween;

		public function CompositeTween() {
			super();
		}
		
		public override function addEventListener( type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false ):void {
			tween.addEventListener( type, delegate );
			super.addEventListener( type, listener, useCapture, priority, useWeakReference );
		}

		public override function removeEventListener(type:String, listener:Function, useCapture:Boolean = false ):void {
			tween.removeEventListener( type, delegate );
			super.removeEventListener( type, listener, useCapture );
		}
		
		/**
		 * delegates the event of the tween
		 */
		private function delegate( e:Event ):void {
			dispatchEvent(e);
		}
		
		public function start():void {
			tween.start();
		}

		public function stop():void {
			tween.stop();
		}
	}
}
